using System;
using System.Configuration;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using DevExpress.Mvvm;
using DevExpress.Xpf.Core;
using DevExpress.Xpf.DemoBase;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using orm.Models;


namespace OneStress {
    public partial class App : Application {
 
 
        async void ShowSplashScreen()
        {
            var viewModel = new DXSplashScreenViewModel()
            {
                Title = "OneStress",
                Subtitle = "Powered by CPET",
                Status = "Starting...",
                Logo = new Uri(@"pack://application:,,,/DevExpress.Xpf.DemoBase.v20.1;component/DemoLauncher/Images/Logo.svg")
            };


            var manager = SplashScreenManager.CreateThemed(viewModel);
            manager.Show(MainWindow);
            for (int i = 0; i <= 100; i++)
            {
                if (i == 50)
                    viewModel.Status = "Loading data...";
                else if (i == 80)
                {
                    viewModel.Status = "Finishing...";
                    await Task.Delay(10);
                }

                viewModel.Progress = i;
                Thread.Sleep(40);
            }
            manager.Close();
            }
            public App() {
                 ShowSplashScreen();

             }


        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            ConfigureContainer();
        }

        private void ConfigureContainer()
        {

            var  filePath = @"..\..\ProjectDB.wdb";
            var con = ConfigurationManager.ConnectionStrings["Sqlite"];

            var dbt = new OneSysDBContext(con.ConnectionString.Replace("*", filePath));
            //dbt.Database.Migrate();
            ServiceContainer.Default.RegisterService("DBSerice", dbt);
   
        }
    }
}
